package com.fs.controller;

import com.fs.annotation.SysLog;
import com.fs.pojo.User;
import com.fs.service.UserService;
import com.fs.vo.PageResult;
import com.fs.vo.SysResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Map;
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @SysLog("添加用户")
    @ApiOperation(value = "添加用户")
    @RequiresPermissions({"user:add"})
    @PostMapping("/add")
    public SysResult addUser(@RequestBody Map<String,Object> request) throws ParseException {
        return userService.addUser(request);
    }

    @SysLog("编辑用户")
    @ApiOperation(value = "编辑用户")
    @RequiresPermissions({"user:edit"})
    @PutMapping("/edit")
    public SysResult editUser(@RequestBody User userEntity){
        return userService.editUser(userEntity);
    }

    @SysLog("用户列表")
    @ApiOperation(value = "用户列表")
    @RequiresPermissions({"user:list"})
    @GetMapping("/list")
    public SysResult list(PageResult request){
        return userService.list(request);
    }

    @SysLog("修改用户状态")
    @ApiOperation(value = "修改用户状态")
    @RequiresPermissions({"user:status"})
    @PutMapping("/status/{id}/{status}")
    public SysResult changeStatus(@PathVariable("id") Integer id,@PathVariable("status") Boolean status){
        return userService.changeStatus(id,status);
    }

    @SysLog("删除用户")
    @ApiOperation(value = "删除用户")
    @RequiresPermissions({"user:del"})
    @DeleteMapping("/{id}")
    public SysResult delById(@PathVariable("id") Integer id){
        return userService.delById(id);
    }

    @SysLog("获取用户信息")
    @ApiOperation(value = "获取用户信息")
    @RequiresPermissions({"user:info"})
    @GetMapping("/get/{id}")
    public SysResult getById(@PathVariable("id") Integer id){
        return userService.getById(id);
    }

}
